<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	//设置默认分类
	$category=pdo_getall('jy_gohome_serve_category',array('uniacid'=>$_SESSION['uniacid']));
	if(empty($category)){
		$inserts=array(
			array('title'=>'上门跑腿','uniacid'=>$_SESSION['uniacid'],'status'=>1,'image'=>'../core/resource/images/diy/default/icon-4.png'),
			array('title'=>'上门配送','uniacid'=>$_SESSION['uniacid'],'status'=>1,'image'=>'../core/resource/images/diy/default/icon-7.png'),
			array('title'=>'家政服务','uniacid'=>$_SESSION['uniacid'],'status'=>1,'image'=>'../core/resource/images/diy/default/icon-6.png'),
			array('title'=>'维修家电','uniacid'=>$_SESSION['uniacid'],'status'=>1,'image'=>'../core/resource/images/diy/default/icon-1.png')
		);
		foreach($inserts as $insert){
			pdo_insert('jy_gohome_serve_category',$insert);
		}
	}
	//显示统计数据
	$order['all']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>1)) + pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>2))+pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>4));
	$day1=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'createtime >'=>strtotime(date('y-m-d'))));
	$day2=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>2,'createtime >'=>strtotime(date('y-m-d'))));
	$day3=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>4,'createtime >'=>strtotime(date('y-m-d'))));
	$order['day']=$day1+$day2+$day3;
	//总业绩
	$day=date("Y-m-d",time("day"));
	$sql1 = "SELECT SUM(pay) FROM " . tablename('jy_gohome_order') . " WHERE uniacid=:uniacid AND status=1";
    $all_money1 = pdo_fetch($sql1,array(":uniacid" => $_SESSION['uniacid']));
	$sql2 = "SELECT SUM(pay) FROM " . tablename('jy_gohome_order') . " WHERE uniacid=:uniacid AND status=2";
    $all_money2 = pdo_fetch($sql2,array(":uniacid" => $_SESSION['uniacid']));
	$sql3 = "SELECT SUM(pay) FROM " . tablename('jy_gohome_order') . " WHERE uniacid=:uniacid AND status=4";
    $all_money3 = pdo_fetch($sql3,array(":uniacid" => $_SESSION['uniacid']));
//	print_r($all_money2);exit;
	//今日业绩
	$sql4 = "SELECT SUM(pay) FROM " . tablename('jy_gohome_order') . " WHERE uniacid=:uniacid AND day=:day AND status=4";
    $today_money1 = pdo_fetch($sql4,array(":uniacid" => $_SESSION['uniacid'],":day" => $day));
	$sql5 = "SELECT SUM(pay) FROM " . tablename('jy_gohome_order') . " WHERE uniacid=:uniacid AND day=:day AND status=2";
    $today_money2 = pdo_fetch($sql5,array(":uniacid" => $_SESSION['uniacid'],":day" => $day));
	$sql6 = "SELECT SUM(pay) FROM " . tablename('jy_gohome_order') . " WHERE uniacid=:uniacid AND day=:day AND status=1";
    $today_money3 = pdo_fetch($sql6,array(":uniacid" => $_SESSION['uniacid'],":day" => $day));
	$money['all']=$all_money1['SUM(pay)']+$all_money2['SUM(pay)']+$all_money3['SUM(pay)'];
	$money['day']=$today_money1['SUM(pay)']+$today_money2['SUM(pay)']+$today_money3['SUM(pay)'];
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	$pindex = max(1, intval($_RQ['page']));
	$psize = 5;
	$total='';
	$fields=array('id','uniacid','title','status','image','remark','pattern','price','work_time','serve_time','times','cancel_time','isshow','paixu','createtime');
	$serve=pdo_getslice('jy_gohome_serve',$params,array($pindex,$psize),$total,$fields,'','paixu desc, id desc');
	$servedatas=array();
	foreach($serve as &$item){
		$servedatas[]=array(
			'name'=>$item['title'],
			'value'=>pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'serve_id'=>$item['id']))
		);
	}
	$fields=array('id','uniacid','mid','name','phone','commission','lev','years','iswx','age','headimg','zhengjian','service','remark','islock','isshow','status','address','createtime');
	$worker=pdo_getslice('jy_gohome_worker',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$workerdatas=array();
	foreach($worker as &$item){
		$workerdatas[]=array(
			'name'=>$item['name'],
			'value'=>pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'worker_id'=>$item['id']))
		);
	}
	$order['table']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	$order['out']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	$order['self']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	$order['yuyue']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	
	$money['table']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	$money['out']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	$money['self']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	$money['yuyue']=pdo_count('jy_gohome_order',array('uniacid'=>$_SESSION['uniacid'],'status'=>3));
	$htmls=array(
		array('type'=>'data','num'=>12,'one_num'=>3,'title'=>'总运营数据','datas'=>array(
			array('title'=>'总订单数','num'=>1,'data'=>$order['all']),
			array('title'=>'订单金额','num'=>1,'data'=>$money['all'].'元'),
			array('title'=>'访客统计','num'=>1,'data'=>1),
			array('title'=>'总用户','num'=>1,'data'=>1),
		)),
		array('type'=>'data','num'=>12,'one_num'=>3,'title'=>'今日运营数据','datas'=>array(
			array('title'=>'订单数','num'=>1,'data'=>$order['day']),
			array('title'=>'订单金额','num'=>1,'data'=>$money['day']),
			array('title'=>'访客统计','num'=>1,'data'=>1),
			array('title'=>'今日用户','num'=>1,'data'=>1),
		)),
		array('type'=>'echarts_pie','one_num'=>2,'width'=>'50%','ecid'=>'wechat','title'=>'服务项目分布图','datas'=>array(
					'time' => date("Y-m-d H:i:s", time()),
					'datas'=>$servedatas,
		)),
		array('type'=>'echarts_pie','one_num'=>2,'width'=>'50%','ecid'=>'wxapp','title'=>'员工业绩分布图','datas'=>array(
					'time' => date("Y-m-d H:i:s", time()),
					'datas'=>$workerdatas,
		)),
	);
	$return=array('htmls'=>$htmls);
	exi($return);
}